Abstract
Include here a description of the whole work, use no more than 400 words, you can use **Bold** and *Italic* highlights, also you can inclue [links](www.iteso.mx). Usually is a good strategy to generate this text at the very end of the process, since you have to include all aspects of the work, from a brief introduction, to problem definitions and methods used, to finally the results found.
This is an introduction, normally, it is done at the very end, when all the other content in the notebook is completed but just before the abstract (which is short version of the introduction) ...
In order to run this notebook, it is necessary to have installed and/or have the requirements.txt file with the following:
The following are the file dependencies that are needed to run this notebook:
%%capture
# Install all the pip packages in the requirements.txt
import sys
!{sys.executable} -m pip install -r requirements.txt
import functions as fn
import sys
import data as dt
import datetime
import visualizations as vs
To complete the project objective, we need to have the data that was created in the laboratory number two. Here are the three stories of operations that will be analize in the next steps.
data_ini_1 = dt.f_leer_archivo(param_estudiante=1)
data_ini_2 = dt.f_leer_archivo(param_estudiante=2)
data_ini_3 = dt.f_leer_archivo(param_estudiante=3)
data_ini_1
| Unnamed: 0 | OpenTime | Symbol | Ticket | Type | Volume | OpenPrice | S/L | T/P | CloseTime | ClosePrice | Profit | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 2021-09-22 05:28:08 | BTCUSD | 45458917 | 0 | 0.23 | 42127.15 | 40139.0 | 42496.76 | 2021-09-22 05:28:17 | 42010.08 | -26.93 |
| 1 | 2 | 2021-09-22 05:30:14 | BTCUSD | 45458934 | 0 | 0.23 | 42060.66 | 40143.0 | 42496.76 | 2021-09-22 10:43:00 | 42501.69 | 101.44 |
| 2 | 4 | 2021-09-22 17:27:04 | BTCUSD | 45470462 | 0 | 0.24 | 42599.23 | 0.0 | 0.00 | 2021-09-22 17:27:55 | 43025.30 | 106.91 |
| 3 | 7 | 2021-09-23 04:09:17 | BTCUSD | 45483777 | 1 | 0.23 | 43179.98 | 44046.0 | 42790.00 | 2021-09-23 06:24:19 | 44050.76 | -200.28 |
| 4 | 9 | 2021-09-24 21:22:51 | BTCUSD | 45524436 | 0 | 0.23 | 42255.15 | 40304.0 | 43135.80 | 2021-09-25 00:39:11 | 43153.89 | 206.71 |
data_ini_2
| Unnamed: 0 | OpenTime | Symbol | Ticket | Type | Volume | OpenPrice | S/L | T/P | CloseTime | ClosePrice | Profit | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2021-09-20 21:38:54 | GBPUSD | 45426490 | 0 | 0.1 | 1.36482 | 1.34191 | 1.41691 | 2021-09-21 18:10:07 | 1.36541 | 5.90 |
| 1 | 2 | 2021-09-21 18:06:22 | EURUSD | 45448836 | 1 | 0.1 | 1.17224 | 1.17272 | 1.17072 | 2021-09-21 19:23:28 | 1.17271 | -4.70 |
| 2 | 3 | 2021-09-22 17:22:53 | AUDUSD | 45470330 | 1 | 0.2 | 0.72540 | 0.73067 | 0.71567 | 2021-09-23 16:47:35 | 0.73067 | -105.40 |
| 3 | 4 | 2021-09-23 16:58:56 | USDCAD | 45498648 | 0 | 0.1 | 1.26548 | 1.26062 | 1.27189 | 2021-09-24 05:42:33 | 1.26699 | 11.92 |
| 4 | 5 | 2021-09-24 19:23:01 | NZDUSD | 45522977 | 0 | 0.1 | 0.70234 | 0.70024 | 70507.00000 | 2021-09-24 23:56:35 | 0.70010 | -22.40 |
data_ini_3
| Unnamed: 0 | OpenTime | Symbol | Ticket | Type | Volume | OpenPrice | S/L | T/P | CloseTime | ClosePrice | Profit | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 2021-09-21 04:36:26 | EURUSD | 45431784 | 1 | 0.10 | 1.172670 | 1.17370 | 1.16980 | 2021-09-21 04:57:00 | 1.1737 | -10.40 |
| 1 | 2 | 2021-09-22 06:36:42 | EURUSD | 45459384 | 0 | 0.25 | 1.172310 | 1.16211 | 1.18220 | 2021-09-22 21:36:26 | 0.0000 | 74.50 |
| 2 | 4 | 2021-09-23 06:01:16 | EURUSD | 45484785 | 0 | 0.50 | 1.170060 | 1.16186 | 1.77991 | 2021-09-23 15:57:25 | 0.0000 | 132.00 |
| 3 | 6 | 2021-09-23 16:03:02 | USDCHF | 45495654 | 0 | 0.70 | 1.370990 | 0.88129 | 0.95338 | 2021-09-24 23:01:56 | 0.0000 | 0.00 |
| 4 | 7 | 2021-09-23 16:08:36 | GBPUSD | 45496076 | 1 | 10.00 | 1.265510 | 1.42103 | 1.33297 | 2021-09-23 16:25:00 | 0.0000 | 957.05 |
| 5 | 9 | 2021-09-23 16:33:58 | USDCAD | 45497181 | 1 | 20.00 | 1.264810 | 1.28521 | 1.25619 | 2021-09-23 21:26:22 | 0.0000 | 1943.07 |
| 6 | 11 | 2021-09-23 21:31:00 | USDCAD | 45504414 | 0 | 0.70 | 0.923620 | 1.24462 | 1.27466 | 2021-09-24 05:11:08 | 0.0000 | 115.01 |
| 7 | 12 | 2021-09-23 21:41:07 | USDJPY | 45504470 | 1 | 25.00 | 110.216000 | 111.20600 | 109.72000 | 2021-09-28 06:25:44 | 111.2060 | -22300.55 |
| 8 | 16 | 2021-09-29 20:21:17 | USDCAD | 45604366 | 1 | 75.00 | 1.276138 | 1.36050 | 1.25604 | 2021-09-30 05:59:52 | 0.0000 | 13765.90 |
| 9 | 20 | 2021-09-30 06:19:10 | USDJPY | 45610096 | 1 | 65.00 | 1.276138 | 114.82900 | 108.82400 | 2021-09-30 18:24:49 | 0.0000 | 17777.56 |
data_jp = fn.f_columnas_tiempos(data_ini_3)
data_jp["mult"] = data_jp.Symbol.map(lambda x: fn.f_pip_size(x))
data_jp = fn.f_columnas_pips(data_jp)
parte_1_jp = fn.f_estadisticas_ba(data_jp)
parte_1_jp['df_1_tabla']
| medida | valor | descripcion | |
|---|---|---|---|
| 0 | Ops totales | 10.00000 | Operaciones totales |
| 1 | Ganadoras | 7.00000 | Operaciones ganadoras |
| 2 | Ganadoras_c | 0.00000 | Operaciones ganadoras de compra |
| 3 | Ganadoras_v | 0.00000 | Operaciones ganadoras de venta |
| 4 | Perdedoras | 2.00000 | Operaciones eprdedoras |
| 5 | Perdedoras_c | 0.00000 | Operaciones perdedoras de compra |
| 6 | Perdedoras_v | 0.00000 | Operaciones eprdedoras de venta |
| 7 | Mediana (Profit) | 1245.41400 | Mediana de profit de operaciones |
| 8 | Mediana (Pips) | 8445.26938 | Mediana de pips de operaciones |
| 9 | r_efectividad | 0.70000 | Ganadoras Totales/Operaciones Totales |
| 10 | r_proporcion | 3.50000 | Ganadoras Totales/Perdedoras Totales |
| 11 | r_efectividad_c | 0.00000 | Ganadoras Compras/Operaciones Totales |
| 12 | r_efectividad_v | 0.00000 | Ganadoras Ventas / Operaciones Totales |
parte_1_jp['df_2_ranking']
| Symbol | rank | |
|---|---|---|
| 0 | EURUSD | 66.67% |
| 1 | GBPUSD | 100.00% |
| 2 | USDCAD | 100.00% |
| 3 | USDCHF | 0.00% |
| 4 | USDJPY | 50.00% |
data_dou = fn.f_columnas_tiempos(data_ini_1)
data_dou["mult"] = data_dou.Symbol.map(lambda x: fn.f_pip_size(x))
data_dou = fn.f_columnas_pips(data_dou)
parte_1_dou = fn.f_estadisticas_ba(data_dou)
parte_1_dou['df_1_tabla']
| medida | valor | descripcion | |
|---|---|---|---|
| 0 | Ops totales | 5.00 | Operaciones totales |
| 1 | Ganadoras | 3.00 | Operaciones ganadoras |
| 2 | Ganadoras_c | 0.00 | Operaciones ganadoras de compra |
| 3 | Ganadoras_v | 0.00 | Operaciones ganadoras de venta |
| 4 | Perdedoras | 2.00 | Operaciones eprdedoras |
| 5 | Perdedoras_c | 0.00 | Operaciones perdedoras de compra |
| 6 | Perdedoras_v | 0.00 | Operaciones eprdedoras de venta |
| 7 | Mediana (Profit) | 37.57 | Mediana de profit de operaciones |
| 8 | Mediana (Pips) | -50391.00 | Mediana de pips de operaciones |
| 9 | r_efectividad | 0.60 | Ganadoras Totales/Operaciones Totales |
| 10 | r_proporcion | 1.50 | Ganadoras Totales/Perdedoras Totales |
| 11 | r_efectividad_c | 0.00 | Ganadoras Compras/Operaciones Totales |
| 12 | r_efectividad_v | 0.00 | Ganadoras Ventas / Operaciones Totales |
parte_1_dou['df_2_ranking']
| Symbol | rank | |
|---|---|---|
| 0 | BTCUSD | 60.00% |
data_ap = fn.f_columnas_tiempos(data_ini_2)
data_ap["mult"] = data_ap.Symbol.map(lambda x: fn.f_pip_size(x))
data_ap = fn.f_columnas_pips(data_ap)
parte_1_ap = fn.f_estadisticas_ba(data_ap)
parte_1_ap['df_1_tabla']
| medida | valor | descripcion | |
|---|---|---|---|
| 0 | Ops totales | 5.000000 | Operaciones totales |
| 1 | Ganadoras | 2.000000 | Operaciones ganadoras |
| 2 | Ganadoras_c | 0.000000 | Operaciones ganadoras de compra |
| 3 | Ganadoras_v | 0.000000 | Operaciones ganadoras de venta |
| 4 | Perdedoras | 3.000000 | Operaciones eprdedoras |
| 5 | Perdedoras_c | 0.000000 | Operaciones perdedoras de compra |
| 6 | Perdedoras_v | 0.000000 | Operaciones eprdedoras de venta |
| 7 | Mediana (Profit) | -22.936000 | Mediana de profit de operaciones |
| 8 | Mediana (Pips) | -11.200000 | Mediana de pips de operaciones |
| 9 | r_efectividad | 0.400000 | Ganadoras Totales/Operaciones Totales |
| 10 | r_proporcion | 0.666667 | Ganadoras Totales/Perdedoras Totales |
| 11 | r_efectividad_c | 0.000000 | Ganadoras Compras/Operaciones Totales |
| 12 | r_efectividad_v | 0.000000 | Ganadoras Ventas / Operaciones Totales |
parte_1_ap['df_2_ranking']
| Symbol | rank | |
|---|---|---|
| 0 | AUDUSD | 0.00% |
| 1 | EURUSD | 0.00% |
| 2 | GBPUSD | 100.00% |
| 3 | NZDUSD | 0.00% |
| 4 | USDCAD | 100.00% |
parte_2_1_dou = fn.f_evolucion_capital(cap_ini=100000, operaciones=data_dou.copy())
parte_2_2_dou = fn.f_estadisticas_mad(parte_2_1_dou, rf=0.05, benchmark_ticker="^GSPC")
parte_2_1_dou
[*********************100%***********************] 1 of 1 completed
| timestamp | profit_d | profit_acm_d | |
|---|---|---|---|
| 0 | 2021-09-22 23:59:59 | 181.42 | 100181.42 |
| 1 | 2021-09-23 23:59:59 | -200.28 | 99981.14 |
| 2 | 2021-09-24 23:59:59 | 0.00 | 99981.14 |
| 3 | 2021-09-25 23:59:59 | 206.71 | 100187.85 |
parte_2_2_dou
| 0 | formato | valor | descripcion | |
|---|---|---|---|---|
| 0 | sharpe_original | Cantidad | -1.54836 | Sharpe Ratio Fórmula Original |
| 1 | sharpe_actualizado | Cantidad | -12.61735 | Sharpe Ratio Fórmula Ajustada |
| 2 | drawdown_capi | Fecha Inicial | 2021-09-22 23:59:59 | Fecha inicial del DrawDown de Capital |
| 3 | drawdown_capi | Fecha Final | 2021-09-23 23:59:59 | Fecha final del DrawDown de Capital |
| 4 | drawdown_capi | DrawDown $ (capital) | -200.28 | Máxima pérdida flotante registrada |
| 5 | drawup_capi | Fecha Inicial | 2021-09-23 23:59:59 | Fecha inicial del DrawUp de Capital |
| 6 | drawup_capi | Fecha Final | 2021-09-25 23:59:59 | Fecha final del DrawUp de Capital |
| 7 | drawup_capi | DrawUp $ (capital) | 206.71 | Máxima ganancia flotante registrada |
parte_2_1_ap = fn.f_evolucion_capital(cap_ini=100000, operaciones=data_ap.copy())
parte_2_2_ap = fn.f_estadisticas_mad(parte_2_1_ap, rf=0.05, benchmark_ticker="^GSPC")
parte_2_1_ap
[*********************100%***********************] 1 of 1 completed
| timestamp | profit_d | profit_acm_d | |
|---|---|---|---|
| 0 | 2021-09-20 23:59:59 | 0.00 | 100000.00 |
| 1 | 2021-09-21 23:59:59 | 1.20 | 100001.20 |
| 2 | 2021-09-22 23:59:59 | 0.00 | 100001.20 |
| 3 | 2021-09-23 23:59:59 | -105.40 | 99895.80 |
| 4 | 2021-09-24 23:59:59 | -10.48 | 99885.32 |
parte_2_2_ap
| 0 | formato | valor | descripcion | |
|---|---|---|---|---|
| 0 | sharpe_original | Cantidad | -6.157319 | Sharpe Ratio Fórmula Original |
| 1 | sharpe_actualizado | Cantidad | -14.128447 | Sharpe Ratio Fórmula Ajustada |
| 2 | drawdown_capi | Fecha Inicial | 2021-09-21 23:59:59 | Fecha inicial del DrawDown de Capital |
| 3 | drawdown_capi | Fecha Final | 2021-09-24 23:59:59 | Fecha final del DrawDown de Capital |
| 4 | drawdown_capi | DrawDown $ (capital) | -115.88 | Máxima pérdida flotante registrada |
| 5 | drawup_capi | Fecha Inicial | 2021-09-20 23:59:59 | Fecha inicial del DrawUp de Capital |
| 6 | drawup_capi | Fecha Final | 2021-09-21 23:59:59 | Fecha final del DrawUp de Capital |
| 7 | drawup_capi | DrawUp $ (capital) | 1.2 | Máxima ganancia flotante registrada |
parte_2_1_jp = fn.f_evolucion_capital(cap_ini=100000, operaciones=data_jp.copy())
parte_2_2_jp = fn.f_estadisticas_mad(parte_2_1_jp, rf=0.05, benchmark_ticker="^GSPC")
parte_2_1_jp
[*********************100%***********************] 1 of 1 completed
| timestamp | profit_d | profit_acm_d | |
|---|---|---|---|
| 0 | 2021-09-21 23:59:59 | -10.40 | 99989.60 |
| 1 | 2021-09-22 23:59:59 | 74.50 | 100064.10 |
| 2 | 2021-09-23 23:59:59 | 3032.12 | 103096.22 |
| 3 | 2021-09-24 23:59:59 | 115.01 | 103211.23 |
| 4 | 2021-09-25 23:59:59 | 0.00 | 103211.23 |
| 5 | 2021-09-26 23:59:59 | 0.00 | 103211.23 |
| 6 | 2021-09-27 23:59:59 | 0.00 | 103211.23 |
| 7 | 2021-09-28 23:59:59 | -22300.55 | 80910.68 |
| 8 | 2021-09-29 23:59:59 | 0.00 | 80910.68 |
| 9 | 2021-09-30 23:59:59 | 31543.46 | 112454.14 |
parte_2_2_jp
| 0 | formato | valor | descripcion | |
|---|---|---|---|---|
| 0 | sharpe_original | Cantidad | -0.016109 | Sharpe Ratio Fórmula Original |
| 1 | sharpe_actualizado | Cantidad | 1.614683 | Sharpe Ratio Fórmula Ajustada |
| 2 | drawdown_capi | Fecha Inicial | 2021-09-24 23:59:59 | Fecha inicial del DrawDown de Capital |
| 3 | drawdown_capi | Fecha Final | 2021-09-28 23:59:59 | Fecha final del DrawDown de Capital |
| 4 | drawdown_capi | DrawDown $ (capital) | -22300.55 | Máxima pérdida flotante registrada |
| 5 | drawup_capi | Fecha Inicial | 2021-09-28 23:59:59 | Fecha inicial del DrawUp de Capital |
| 6 | drawup_capi | Fecha Final | 2021-09-30 23:59:59 | Fecha final del DrawUp de Capital |
| 7 | drawup_capi | DrawUp $ (capital) | 31543.46 | Máxima ganancia flotante registrada |
final_dict_dou = fn.f_be_de(data_dou)
final_dict_dou
++++ init_login succeded, message = True sin ocurrencias
final_dict_ap = fn.f_be_de(data_ap)
final_dict_ap
++++ init_login succeded, message = True
{'ocurrencias': {'Cantidad': 1,
'ocurrencia_1': {'timestamp': Timestamp('2021-09-21 18:10:07'),
'operaciones': {'ganadoras': {'instrumento': 'GBPUSD',
'volumen': 0.1,
'sentido': 'buy',
'profit_ganadora': 5.9},
'perdedoras': {'instrumento': 'EURUSD',
'volumen': 0.1,
'sentido': 'buy',
'profit_perdedora': -0.0}},
'ratio_cp_profit_acm': 0.0,
'ratio_cg_profit_acm': 1.0,
'ratio_cp_cg': 0.0}},
'resultados': {'dataframe': ocurrencias status_quo aversion_perdida sensibilidad_decreciente
0 1 100.0% 0.0% No}}
final_dict_jp = fn.f_be_de(data_jp)
final_dict_jp
++++ init_login succeded, message = True
{'ocurrencias': {'Cantidad': 4,
'ocurrencia_1': {'timestamp': Timestamp('2021-09-23 16:25:00'),
'operaciones': {'ganadoras': {'instrumento': 'GBPUSD',
'volumen': 10.0,
'sentido': 'sell',
'profit_ganadora': 957.05},
'perdedoras': {'instrumento': 'USDCHF',
'volumen': 0.7,
'sentido': 'sell',
'profit_perdedora': 0.31}},
'ratio_cp_profit_acm': 0.0,
'ratio_cg_profit_acm': 0.83,
'ratio_cp_cg': 0.0},
'ocurrencia_2': {'timestamp': Timestamp('2021-09-23 21:26:22'),
'operaciones': {'ganadoras': {'instrumento': 'USDCAD',
'volumen': 20.0,
'sentido': 'sell',
'profit_ganadora': 1943.07},
'perdedoras': {'instrumento': 'USDCHF',
'volumen': 0.7,
'sentido': 'sell',
'profit_perdedora': 0.31}},
'ratio_cp_profit_acm': 0.0,
'ratio_cg_profit_acm': 0.63,
'ratio_cp_cg': 0.0},
'ocurrencia_3': {'timestamp': Timestamp('2021-09-24 05:11:08'),
'operaciones': {'ganadoras': {'instrumento': 'USDCAD',
'volumen': 0.7,
'sentido': 'buy',
'profit_ganadora': 115.01},
'perdedoras': {'instrumento': 'USDCHF',
'volumen': 0.7,
'sentido': 'buy',
'profit_perdedora': 0.31}},
'ratio_cp_profit_acm': 0.0,
'ratio_cg_profit_acm': 0.04,
'ratio_cp_cg': 0.0},
'ocurrencia_4': {'timestamp': Timestamp('2021-09-24 05:11:08'),
'operaciones': {'ganadoras': {'instrumento': 'USDCAD',
'volumen': 0.7,
'sentido': 'buy',
'profit_ganadora': 115.01},
'perdedoras': {'instrumento': 'USDJPY',
'volumen': 25.0,
'sentido': 'buy',
'profit_perdedora': -6.63}},
'ratio_cp_profit_acm': 0.0,
'ratio_cg_profit_acm': 0.04,
'ratio_cp_cg': 0.06}},
'resultados': {'dataframe': ocurrencias status_quo aversion_perdida sensibilidad_decreciente
0 4 100.0% 0.0% No}}
# Ranking
parte_1_ap['df_2_ranking']['rank'] = parte_1_ap['df_2_ranking']['rank'].map(lambda x: eval(x[:-1]))
vs.pie_chart(parte_1_ap['df_2_ranking'], title="Ranking Ana Paula")
parte_1_dou['df_2_ranking']['rank'] = parte_1_dou['df_2_ranking']['rank'].map(lambda x: eval(x[:-1]))
vs.pie_chart(parte_1_dou['df_2_ranking'], title="Ranking Douglas")
parte_1_jp['df_2_ranking']['rank'] = parte_1_jp['df_2_ranking']['rank'].map(lambda x: eval(x[:-1]))
vs.pie_chart(parte_1_jp['df_2_ranking'], title="Ranking Juan Pablo")
# DrawDown and DrawUp
vs.line_chart(parte_2_1_ap, parte_2_2_ap)
vs.line_chart(parte_2_1_jp, parte_2_2_jp)
vs.line_chart(parte_2_1_dou, parte_2_2_dou)
# Disposition Effect
vs.chart_behave(final_dict_dou)
sin ocurrencias
vs.chart_behave(final_dict_ap)
vs.chart_behave(final_dict_jp)
[1] Munnoz, 2020. Python project template. https://github.com/iffranciscome/python-project. (2021).